package com.yingside.collection;

import java.util.ArrayList;

public class TestGeneral {
    public static void main(String[] args) {
        //没有泛型的集合产生的问题
        /*ArrayList list = new ArrayList();
        list.add("hello");
        list.add(123);
        list.add(9.9);
        list.add(true);

        Student s1 = new Student(1,"张三","139999999");
        list.add(s1);

        // ArrayList可以往里面放入任意类型的值
        for (int i = 0; i < list.size(); i++) {
            Object obj = list.get(i);
            if(obj instanceof Student){
               Student stu = (Student)obj;
                System.out.println(stu.getName());
            }
        }*/


//        ArrayList<String> list = new ArrayList<String>();
//        list.add("abc");

        ArrayList<Student> list = new ArrayList<>();
        Student s1 = new Student(1,"张三1","1243453461");
        Student s2 = new Student(2,"张三2","1243453462");
        Student s3 = new Student(3,"张三3","1243453463");
        list.add(s1);list.add(s2);list.add(s3);

        System.out.println("===============原始集合==================");

        for (int i = 0; i < list.size(); i++) {
            Student student = list.get(i);
            System.out.println("student = " + student);
        }

        boolean contains = list.contains(new Student(1,"张三1","1243453461"));
        System.out.println("contains = " + contains);

        Student student = list.get(0);
        student.setId(222);
        student.setName("宁宁");
        student.setTel("22222");

        System.out.println("===============修改之后==================");
        for (int i = 0; i < list.size(); i++) {
            Student s = list.get(i);
            System.out.println("student = " + s);
        }

        //封装一个学生管理类
        //学生类 id，name，tel
        //这个类可以处理学生相关的操作
        //学生的添加，学生的id查找，学生集合的显示，学生id的删除


    }
}
